
import Vue from 'vue'
import axios from 'axios'
import qs from 'qs'
import { Message, MessageBox, Loading } from 'element-ui'

// const _ = function () {
//     var arr = [].slice.call(arguments);
//     console.log(arr.join('~~~~~~~'));
// }
// axios 配置
function axioxConfig(){
    axios.defaults.timeout = 10000;
    let AUTO_TOKEN = localStorage.getItem('token');
    if(AUTO_TOKEN){
        axios.defaults.headers = {
            'Access-Token':AUTO_TOKEN,
            'Content-Type': 'application/json'
        }
    }else{
        axios.defaults.headers = {
            'Accept':'*/*',
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
        }
    }
}
axioxConfig();

console.log('this is qing')
console.log(process.env.NODE_ENV)
// axios.defaults.baseURL = 'https://192.168.10.113:8090/';
// axios.defaults.baseURL = 'https://braidapi.beiface.com/';
// axios.defaults.baseURL = 'https://braidapit.beiface.com/';
let changeUrl = (process.env.NODE_ENV == 'development') ? 'https://braidapit.beiface.com/' : (process.env.NODE_ENV == 'hmbuild') ? 'http://braidapi.henm.cn/' : 'https://braidapi.beiface.com/'
axios.defaults.baseURL = changeUrl
// 请求处理
axios.interceptors.request.use(function (config) {
    // if(config.method  === 'post'){
    //     config.data = qs.stringify(config.data)
    // }
    // 在发送请求之前做些什么
    return config
  }, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error)
  });
//返回状态判断
axios.interceptors.response.use(function (response) {
  // 对响应数据做点什么
  return response
}, function (error) {
  // 对响应错误做点什么
  return Promise.reject(error)
});


function comAjax(opt) {
    opt.url = opt.url || '';
        if (opt.type === 'get') {
            return axios.get(opt.url)
        } else if (opt.type === 'post') {
            return axios.post(opt.url, opt.data)
        }else if (opt.type === 'put') {
            return axios.put(opt.url, opt.data)
        }
    // }
}


function get(data , url) {
    for (var i in data) {
        if (data.hasOwnProperty(i)) {
            if (url.indexOf('?') >= 0) {
                url += '&' + i + '=' + data[i]
            } else {
                url += '?' + i + '=' + data[i]
            }
        }
    }
    return comAjax({
        type: 'get',
        url,
        data
    })
}


// 登陆
export const logining = function (data) {
    return comAjax({
        data: data,
        type: 'post',
        url:'token/password'
    })
};

//查询-用户所属角色查询
export const myRole = function (data) {
    return get(data,'role/user/relation/userId')
};

//查询所有角色-排序
export const roles = function (data) {
    return get(data,'role/all')
};

//用户所属角色查询
// export const myPotence = function (data) {
//     return get(data,'role/user/relation/userId')
// }

//查询所有权限-排序
export const potence = function (data) {
    return get(data,'permisssion/all/tier')
};

//查询-绑定的后端资源权限
export const rolePotence = function (data) {
    return get(data,'role/permisssion/relation/roleId')
};


//绑定-接口资源权限
export const bindPotence = function (data) {
    return comAjax({
        data: data,
        type:'post',
        url:'role/permisssion/relation/multiple'
    })
};

//创建角色
export const creatRole = function (data) {
    return comAjax({
        data: data,
        type:'post',
        url:'role'
    })

};

//查询-所有的菜单
export const allMenu = function (data) {
    return get(data,'permisssion/website/all/tier')
};

//查询-绑定的菜单
export const roleMenu = function (data) {
    return get(data,'role/permisssion/website/relation/roleId')
};

//绑定-菜单资源权限用ajax


//菜单-根据级别查询
export const parMenu = function (data) {
    return get(data,'permisssion/website/type')
};

//菜单-添加
export const addMenu = function (data) {
    return comAjax({
        data: data,
        type:'post',
        url:'permisssion/website'
    })

};
//后台资源权限-添加
export const addPotence = function (data) {
    return comAjax({
        data: data,
        type:'post',
        url:'permisssion'
    })

};

//查询-门店列表
export const allstore = function (data) {
    return get(data,'shop/all/status')
};



//用户-查询
export const user = function (data) {
    return get(data,'role/user/relation/internal/page')
};

//用户绑定的门店
export const userSope = function (data) {
    return get(data,'shop/user/relation/userId')
};

//用户绑定门店
export const userBindShop = function (data) {
    return comAjax({
        data: data,
        type:'post',
        url:'shop/user/relation/multiple'
    })

};

//服务项目查询
export const getServer = function (data) {//获取项目分组标题
    return comAjax({
        type:'get',
        url:'serviceItem/group/all/status?direction=DESC&propertys=createdTime&status=NORMAL'
    })
};

export const addSIService = function (data) {
    return comAjax({
        data: data,
        type:'post',
        url:'serviceItem/group'
    })
};

export const attachments = function (data) {
    return comAjax({
        data: data,
        type:'post',
        url:'attachments?fileName=111'
    })
};
export const reuseItem = function (data) { //复用
    return comAjax({
        data: data,
        type:'put',
        url:'serviceItem/reuse?id='+ data
    })
};

export const getItemService = function (data) {
    return comAjax({
        type:'get',
        url:'serviceItem?id=' + data
    })
};
export const addLIService = function (data) {
    return comAjax({
        data: data,
        type:'post',
        url:'serviceItem'
    })
};
export const editLIService = function (data) {
    return comAjax({
        data: data,
        type:'put',
        url:'serviceItem?id=' + data.id
    })
};
export const getLIService = function (data) {
    return comAjax({
        type:'get',
        url:'serviceItem/group/status?groupId=' +data.groupId+ '&status='+data.status
    })
};
export const deleteServerItem_As = function (data) {
    return comAjax({
        data: data,
        type:'put',
        url:'serviceItem/group/delete?id=' + data
    })
};
export const deleteServerItemInfo_As = function (data) {
    return comAjax({
        data: data,
        type:'put',
        url:'/serviceItem/delete?id=' + data
    })
};

//门店
export const ajaxGet = function (url) {
    axioxConfig();
    return comAjax({
        type:'get',
        url:url
    })
};
export const storeAsGet = function (url) {
    return comAjax({
        type:'get',
        url:url
    })
};
export const storeAsPost = function (data,url) {
    return comAjax({
        data:data,
        type:'post',
        url:url
    })
};
export const storeAsPut = function (url,data) {
    return comAjax({
        data:data,
        type:'put',
        url:url
    })
};

//banner
export const bannerList = function (data) {
    return get(data,'/banners/type?bannerType=MINI_APP')
};


//推广
//省
export const provinceList = function (data) {
    return get(data,'/global/basicdata/getAllProvinceList')
};

export const proareaList = function (data) {
    return get(data,'/promote/area/province')
};

//咨询
//人员
export const groupList = function (data) {
    return get(data,'/counselorDept/list?direction=DESC&propertys=name&startTime=2008-10-08%2000:00:00&endTime=2038-10-08%2017:16:38')
};


/* 文章块 */
/* 文章列表 */
export const articlesList = function (data) {
        return comAjax({
            data: data,
            type: 'get',
            url: '/forum/articles/strategies?page=' + data.page + '&size=' + data.size
        })
};
/* 文章新增 */
export const addArticles = function (data) {
        return comAjax({
            data: data,
            type: 'post',
            url: '/forum/articles'
        })
};
/* 文章修改 */
export const editArticles = function (data) {
    return comAjax({
        data: data,
        type: 'put',
        url: '/forum/articles?id=' + data.id
    })
};
/* 文章删除 */
export const delArticles = function (data) {
    return comAjax({
        data: data,
        type: 'put',
        url: '/forum/articles/delete?id=' + data.id
    })
};
/* 文件上传 */
export const articlesUpload = function (data) {
    return comAjax({
        data: data,
        type: 'post',
        url: '/system/ueditor/imgUpload'
    })
};
